package com.hn.zhijian.base.common;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @program: carl-main
 * @description: 异常统一处理
 * @author: carl
 * @create: 2019-12-08 12:16
 **/
//@Configuration
public class ErrorPageConfig implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        /*1、按错误的类型显示错误的网页*/
        /*错误类型为404，找不到网页的，默认显示404.html网页*/
        ErrorPage e404 = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
        /*错误类型为500，表示服务器响应错误，默认显示500.html网页*/
        ErrorPage e400 = new ErrorPage(HttpStatus.BAD_REQUEST, "/400");
        ErrorPage e401 = new ErrorPage(HttpStatus.BAD_REQUEST, "/401");
        registry.addErrorPages(e400, e404,e401);
    }
}
